package com.planegame.Obj;

import com.planegame.GameWin;
import com.planegame.utils.Gameutils;

import java.awt.*;

//敌方飞机小兵
public class EnemyObj extends GameObject{
    public int flag=1;

    public EnemyObj() {
        super();
    }

    public EnemyObj(Image img, int x, int y, double speed) {
        super(img, x, y, speed);
    }

    public EnemyObj(int x, int y, int width, int hight) {
        super(x, y, width, hight);
    }

    public EnemyObj(Image img, int x, int y, int width, int hight, double speed, GameWin frame) {
        super(img, x, y, width, hight, speed, frame);
    }

    @Override
    public void paintSelf(Graphics gImage) {
        super.paintSelf(gImage);
        y+=speed;
        if(flag==1){
            x+=speed;
        }
        else if(flag==-1)
        {
            x-=speed;
        }
        if(x>=550)flag=-1;
        if(x<=0)flag=1;
        //每次绘制之后判断是否与每一颗子弹碰撞
        for(ShellObj shellObj: Gameutils.shellObjList){
            if(this.getRec().intersects(shellObj.getRec())){
                //子弹和敌机消失前移动到某个点，保证后面飞机之间碰撞判断正常
              shellObj.setX(-100);
              shellObj.setY(100);
              this.x=-200;this.y=200;
              Gameutils.removeList.add(shellObj);
              Gameutils.removeList.add(this);
            }
        }
            if (this.getRec().intersects(this.frame.planeObj.getRec())) {//注意这个this.frame，很搞
                GameWin.state=3;
            }
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }
}
